home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 29
/
Volume 29 - JOGO DISK .iso
/
Games
/
jungle_adventure.swf
/
scripts
/
__Packages
/
GameCollectable.as
< prev
next >
Wrap
Text File
|
2006-11-29
|
2KB
|
53 lines
class GameCollectable extends SSObject
{
var classID = SSGlobal.CLSID_COLLECTABLE;
var collisionMask = SSGlobal.CLSID_SHAPE | SSGlobal.CLSID_MAINCHAR;
var collected = false;
var radius = 15;
var bounciness = 0.5;
function GameCollectable()
{
super();
}
function updatePosition(elapsed)
{
var _loc3_ = this.x;
var _loc2_ = this.y;
this.checkCollisions(elapsed);
this.moveBy(this.velocity.x * this.motionTime,this.velocity.y * this.motionTime,0);
if(Math.abs(_loc3_ - this.x) < 0.5 && Math.abs(_loc2_ - this.y) < 0.5)
{
this.x = _loc3_;
this.y = _loc2_;
if((this.inMotion -= elapsed) <= 0)
{
this.cancelUpdates();
this.velocity.loc(0,0,0);
}
}
}
function checkCollision(obj)
{
var _loc2_ = undefined;
switch(obj.classID & 4294901760)
{
case SSGlobal.CLSID_SHAPE:
if(_loc2_ = SSCollision.sweepSphereToStaticShape(this,obj))
{
var _loc3_ = this.velocity.__get__length() * this.bounciness;
var _loc5_ = this.motionDir.dot(_loc2_.normal);
this.velocity.x = (this.motionDir.x - _loc2_.normal.x * _loc5_ * 2) * _loc3_;
this.velocity.y = (this.motionDir.y - _loc2_.normal.y * _loc5_ * 2) * _loc3_;
this.x = _loc2_.point.x;
this.y = _loc2_.point.y;
}
break;
case SSGlobal.CLSID_MAINCHAR:
if(SSCollision.sweepSphereToSphere(this,obj,true))
{
this.setCollected(obj);
}
}
}
}